<?php

namespace Home\Controller;

/**
 * 房型页面controller
 * @modify trainyao 2016-01-04 创建
 */
class RoomPageController extends \Home\Controller\ParentController {

    /**
     * 房型展示页面
     * @modify trainyao 2016-01-04    创建
     */
    public function index() {
        $hotelId = $this->hotelId;

        if (!empty($hotelId)) {
            // 房型和房间号
            $roomTypeLogic = A('Common/RoomType', 'Logic');
            $roomInfo = $roomTypeLogic->getInfoByHotel($hotelId);
            $roomNames = array();
            // 处理数据
            foreach ($roomInfo as &$room) {
                $room['roomNames'] = array_column($room['room'], 'name');
                $roomNames = array_merge($roomNames, $room['roomNames']);
                $room['roomNames'] = implode(',', $room['roomNames']);

                $roomData = array();
                foreach ($room['room'] as $roomItem) {
                    array_push($roomData, $roomItem['id'] . ':' . $roomItem['name']);
                }
                $room['roomData'] = implode(',', $roomData);
            }
            unset($room);

            $this->assign('rooms', $roomInfo);
            $this->assign('roomNames', $roomNames);


            // 查询是否登陆过锁掌柜
            $hotelInfo = A('Common/Hotel', 'Logic')->getHotelByHotelId($hotelId);
            if (!empty($hotelInfo) && !empty($hotelInfo[0]['communityno'])) {
                $this->assign('hasQRMLogin', true);
                // 查询锁掌柜的房间供前端对比
                $roomLogic = A('Common/Room', 'Logic');
                $qrmRoomData = $roomLogic->getQrmRoom($hotelId);
                $qrmRoomNames = array();
                foreach ($qrmRoomData as $qrmRoom) {
                    $qrmRoomNames[] = $qrmRoom['no'];
                }

                $this->assign('qrmRoomNames', $qrmRoomNames);
            }

            // 是否是义卖客栈
            $result = $this->checkUsageHotel($hotelId);
            // 是否开启畅联代收
            $isPayUclbrt = $this->checkIsUclbrtPay($hotelId);

            $this->assign('isPayUclbrt', $isPayUclbrt);
            $this->assign('isFreeHotel', $result['isFreeHotel']);

            // 获取已申请客栈
            $userId = getUserId();
            $adminInfo = D('AdminLogin')->getInfo($userId);
            $applyHotel = D('HotelApply')->getInfoByMobileAndAreaCode($adminInfo['mobile'], $adminInfo['areacode'], array(0,2));
            $this->assign('applyHotel',$applyHotel);

            //获取区号时区数据
            $HotelLogic = A('Common/Hotel', 'Logic');
            $universalTimeData = $HotelLogic->universalTimeList();
            $this->assign('universalTimeList', $universalTimeData);

            // 获取系统货币
            $currencyLogic = A('Common/Currency', 'Logic');
            $currencyData = $currencyLogic->getBpCurrency($hotelId);
            $currencyData = my_sort($currencyData, 'type', SORT_DESC);
            $currencyDefaultData = my_sort($currencyData, 'type', SORT_DESC)[0];

            $this->assign('currencyInfo', $currencyData);
            $this->assign('currencyDefaultInfo', $currencyDefaultData);
        }
        $this->display();
    }

}
